package com.kun.service_edu.controller;


import com.kun.service_edu.client.VodClient;
import com.kun.service_edu.entity.EduVideo;
import com.kun.service_edu.service.EduVideoService;
import com.kun.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-10-04
 */
@RestController
@RequestMapping("/service_edu/edu-video")
@CrossOrigin
public class EduVideoController {
    @Autowired
    private EduVideoService eduVideoService;
    @Autowired
    private VodClient vodClient;
    @PostMapping("addVideo")
    public R addVideo(@RequestBody EduVideo eduVideo){
        eduVideoService.save(eduVideo);
        return R.ok();
    }
    @PostMapping("delVideo/{videoId}")
    public R delVideo(@PathVariable String videoId){
        EduVideo eduVideo= eduVideoService.getById(videoId);
        String videoSourceId = eduVideo.getVideoSourceId();
        System.out.println(videoSourceId);
        if (videoSourceId!=null) {
            vodClient.delVideo(videoSourceId);
        }
        eduVideoService.removeById(videoId);
        return R.ok();
    }
    @PostMapping("getVideoById/{videoId}")
    public R getVideoById(@PathVariable String videoId){
        EduVideo video = eduVideoService.getById(videoId);
        System.out.println(video);
        return R.ok().data("video",video);
    }
    @PostMapping("updateVideo")
    public R updateVideo(@RequestBody EduVideo eduVideo){
        eduVideoService.updateById(eduVideo);
        return R.ok();
    }
//    @DeleteMapping("delete-batch")
//    public R delete_batch(@RequestParam("videoIdList") List videoIdList){
//        eduVideoService.removeVideoByIds(videoIdList);
//        return R.ok();
//    }

}

